package com.moyu.crowdsource.util;

import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CommonErrorHandle {

    public static Map<String, Object> getErrorInfo(BindingResult bindingResult){
        Map<String, Object> map = new HashMap<String, Object>();
        List<FieldError> errors = bindingResult.getFieldErrors();
        for (FieldError fieldError : errors) {
        /*System.out.println("错误字段名" + fieldError.getField());
        System.out.println("错误信息" + fieldError.getDefaultMessage());*/
            map.put(fieldError.getField(), fieldError.getDefaultMessage());
        }
        return map;
    }
}
